package com.gitee.andy.rpc.entity;

import java.io.Serializable;
import java.util.Arrays;

import org.apache.commons.lang3.builder.ToStringBuilder;

public class RpcMethodId implements Serializable {
	private static final long serialVersionUID = -892005513614283018L;

	private String serviceName;
	private String methodName;
	private Class<?>[] parameterTypes;

	public RpcMethodId(String serviceName, String methodName, Class<?>[] parameterTypes) {
		super();
		this.serviceName = serviceName;
		this.methodName = methodName;
		this.parameterTypes = parameterTypes;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
		result = prime * result + Arrays.hashCode(parameterTypes);
		result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RpcMethodId other = (RpcMethodId) obj;
		if (methodName == null) {
			if (other.methodName != null)
				return false;
		} else if (!methodName.equals(other.methodName))
			return false;
		if (!Arrays.equals(parameterTypes, other.parameterTypes))
			return false;
		if (serviceName == null) {
			if (other.serviceName != null)
				return false;
		} else if (!serviceName.equals(other.serviceName))
			return false;
		return true;
	}

	@Override
	public String toString() {
		ToStringBuilder builder = new ToStringBuilder(this);
		builder.append("serviceName", serviceName);
		builder.append("methodName", methodName);
		builder.append("parameterTypes", Arrays.toString(parameterTypes));
		return builder.toString();
	}

}
